﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using AAA.Chart.Component;

namespace AAA.Chart.Style
{
    public class PriceVolumeChart : DefaultDrawMethod
    {
        public override void Draw(System.Drawing.Graphics g)
        {
            Pen pen = new Pen(new SolidBrush(ForeColor), Width);
            Pen penCurrentPrice = new Pen(new SolidBrush(Color.Red), Width);
            int[] iStart;
            int[] iEnd;

            for (int i = StartIndex; i < EndIndex; i++)
            {
                try
                {
                    iStart = ChartMeta.ValueToPixel(0,
                                                    YDataSource[i]);
                    iEnd = ChartMeta.ValueToPixel(XDataSource[i],
                                                  YDataSource[i]);
                    
                    if(IsValidate(iStart) && IsValidate(iEnd))
                        g.DrawLine(YDataSource[i] == LastPrice ? penCurrentPrice : pen, new Point(iStart[0], iStart[1]), new Point(iEnd[0], iEnd[1]));
                }
                catch (Exception ex)
                {
                    Console.WriteLine(ex.Message + "," + ex.StackTrace);
                }
            }
        }
    }
}
